const util = require("../utils/util")

/**
 * 成长卡列表
 * @param {*} params {page:String,page_size:String,success:(Function)}
 */
const cardList = function (params) {
  let url = util.getBaseUrl() + "/api/member/cardList";
  let data = {
    token: util.getToken(),
    page: params.page,
    page_size: params.page_size,
  };

  util.request({
    url: url,
    method: "GET",
    data: data,
    success(res) {
      // console.log("res", res)
      params.success(res)
    }
  })
}

/**
 * 当前在售成长卡
 * @param {Object} params {success{Function}成功回调函数}
 */
const cardOnsale = function (params) {
  let url = util.getBaseUrl() + "/api/member/cardOnsale";
  let data = {
    token: util.getToken(),
    is_share:params.is_share,
    channel:params.channel,
  };

  util.request({
    url: url,
    method: "GET",
    data: data,
    success(res) {
      // console.log("res", res)
      params.success(res)
    }
  })
}

/**
 * 成长卡激活
 * @param {Object} params {member_card_id{String},success{Function}}
 */
const activeCard = function (params) {
  let url = util.getBaseUrl() + "/api/member/activeCard";
  let data = {
    token: util.getToken(),
    member_card_id: params.member_card_id,
  };

  util.request({
    url: url,
    method: "POST",
    data: data,
    success(res) {
      // console.log("res", res)
      params.success(res)
    }
  })
}

/**
 * 新增宝宝信息
 * @param {Object} params {nickname{String},sex{String},birthday{String}}
 */
const addBaby = function (params) {
  let url = util.getBaseUrl() + "/api/member/addBaby";
  let data = {
    token: util.getToken(),
    nickname: params.nickname,
    sex: params.sex,
    birthday: params.birthday,
    height: params.bheight,
    weight: params.bweight,
  };

  util.request({
    url: url,
    method: "POST",
    data: data,
    success(res) {
      // console.log("res", res)
      params.success(res)
    }
  })
}

    /**
   *  成长卡兑换
   */
  const cardExchange = function (params) {
    let url = util.getBaseUrl() + "/api/member/cardExchange";
    let data = {
      token:params.token?params.token:util.getToken(),
      card_sn: params.card_sn,
    };
    util.request({
      url: url,
      method: "POST",
      data: data,
      success(res) {
        params.success(res)
      }
    })
  }

  /**
 * 当前在售成长卡
 * @param {Object} params {success{Function}成功回调函数}
 */
const getServicesList = function (params) {
  let url = util.getBaseUrl() + "/api/member/getServicesList";
  let data = {
   // token: util.getToken(),
  };
  util.request({
    url: url,
    method: "GET",
    data: data,
    success(res) {
      params.success(res)
    }
  })
}

    /**
   *  成长卡兑换
   */
     const cardDExchange = function (params) {
      let url = util.getBaseUrl() + "/api/member/cardExchange";
      let data = {
        token:params.token?params.token:util.getToken(),
        card_sn: params.card_sn,
        is_active:params.is_active,
        channel:params.channel
      };
      util.request({
        url: url,
        method: "POST",
        data: data,
        success(res) {
          params.success(res)
        }
      })
    }


module.exports = {
  cardList,
  cardOnsale,
  activeCard,
  addBaby,
  cardExchange,
  cardDExchange,
  getServicesList
}